import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// 抑制开发环境 ResizeObserver 的已知报错（不影响功能）
if (typeof window !== 'undefined') {
  const ignoreResizeObserverError = (e) => {
    const msg = e?.message || e?.reason?.message || ''
    if (msg && (msg.includes('ResizeObserver loop') || msg.includes('ResizeObserver loop limit exceeded'))) {
      e.stopImmediatePropagation?.()
      e.preventDefault?.()
      return true
    }
    return false
  }
  window.addEventListener('error', (e) => { ignoreResizeObserverError(e) })
  window.addEventListener('unhandledrejection', (e) => { ignoreResizeObserverError(e) })
}

const app = createApp(App)
app.use(ElementPlus)
app.use(router)
app.use(store)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.mount('#app')
